num = input()
if len(num) == 4:
    possible = []
    for i in range(1, 5):
        for j in range(0, 4):
            if i + j <= 4:
                possible.append(int(num[j:i+j]))
    prime_numbers = [num for num in possible if all(num % i != 0 for i in range(2, int(num**0.5) + 1)) and num > 1]
    if prime_numbers:
        prime_numbers.sort(reverse = True)
        print(prime_numbers[0])
    else:
        print(0)
else:
    print(0)
